/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package admin;

import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.DataWrapper;
import model.Inventory;

/**
 *
 * @author moustafa
 */
public class RecoverInv extends HttpServlet {

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException{

    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException{
        DataWrapper wrapper = DataWrapper.getInstance();
        int deffIndex = (Integer)request.getSession(false).getAttribute("deff_index");
        Inventory targetInv = ((ArrayList<Inventory>)request.getSession(false).getAttribute("defficiencies")).get(deffIndex);
        int suppIndex = Integer.parseInt(request.getParameter("supp_index"));
        Inventory sourceInv = ((ArrayList<Inventory>)request.getSession(false).getAttribute("supplementaries")).get(suppIndex);
        wrapper.recover(targetInv, sourceInv);
        response.sendRedirect("../admin");
    }

}
